/**
 *This program name is SystemAction use for System actions.
 *Copyright (C) 2012  Novin

 *This program is free software; you can redistribute it and/or
 *modify it under the terms of the GNU General Public License
 *as published by the Free Software Foundation; either version 2
 *of the License, or (at your option) any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program; if not, write to the Free Software
 *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */
package org.novin.programs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
 *
 * @author Acer
 */
public final class SystemActions {

    // get Path values in list
    public static List<String> pathValues(){
        
        /// Initialisation
        List list = new ArrayList<String>();
        String value = System.getenv("path");
        
        StringTokenizer st;
        String token;
        
        String os = System.getProperty("os.name");
        
        ///check Os is window or Unix, linux
        if(os.startsWith("window"))
        {
            st = new StringTokenizer(value,";");
        }
        else{
            st = new StringTokenizer(value,":");
        }
        
        // adding tokens to list        
        while(st.hasMoreTokens()){
            token = st.nextToken(";");
            list.add(token);
           
        }
        return list;
    }
    
    
    //get processes in window operating system
    public static List getProcesses() throws IOException{
        final String command = "tracklist /NH";
        
        ArrayList list = new ArrayList();
        
         Runtime runtime = Runtime.getRuntime();
         Process p = runtime.exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe ");
         BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
         String line = "";
         line = br.readLine();
         while(line != null){
            list.add(line);
            line = br.readLine();
         }
         
         return list;
    }
    
    
}
